#ifndef BOT_H_
#define BOT_H_

#include "State.h"
#include "fieldgenerator.h"

#include <map>
#include <vector>
#include <utility>

class PathQueueEntry {
public:
    Location antLoc;
    std::stack<int> path;
public:
    PathQueueEntry(const Location& loc,
		   const std::stack<int>& antpath):antLoc(loc),path(antpath) {}
    bool operator < (const PathQueueEntry& other) const{
	return path.size() < other.path.size();
    }
};

typedef std::priority_queue<PathQueueEntry> PathQueue;

/*
    This struct represents your bot in the game of Ants
*/

class Bot
{
private:
    State state;
    PotentialField field;
    std::map< int , std::vector<Location> > squadList;
    std::map< Location,bool > inSquad;
    std::map< Location,bool > processedAnts;
public:
    Bot();

    void playGame();    //plays a single game of Ants

    void makeMoves();   //makes moves for a single turn
    void endTurn();     //indicates to the engine that it has made its moves
private:
    //individual ant moves
    void randomMove(int ant);
    bool huntFood(int ant);
    bool huntAnts(int ant);
    bool potentialBasedMove(const Location& ant);

    bool isLocationContested(const Location& nLoc) const;
    int  resolveBattle(const Location& nLoc) ;

    //Squad management  functions
    void buildSquads();
    void moveSquad(const int& squad_id);
    bool isInSquad(const Location& ant) const;
    void clearSquads();
    bool moveSquadTo(std::vector<Location>::iterator start,
		     std::vector<Location>::iterator end,
		     const Location& loc,int& shortestPathLen);
    bool moveAntTo(const Location& ant,const Location& target);
    void printSquad(const int& squad_id) ;


    //Squad objective functions
    bool squadHuntFood(const int& squad_id);
    bool squadHuntAnt(const int& squad_id);
    bool squadPotentialBasedMove(const int& squad_id);
    //returns a list of paths for each ant in squad to loc
    PathQueue generateSquadMoves(std::vector<Location>::iterator start,
				 std::vector<Location>::iterator end,
				 const Location& loc);
    void moveToFrontLine(const int& squad_id);
};

#endif //BOT_H_
